package com.vanzo.some;

import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;

/**
 * Created by tisen on 2017/6/9.
 */

public class TipDialog extends Dialog implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private Context context;
    private RollPagerView rollPagerView;
    private ImageView cancel;

    private TipClickListener listener = null;

    public void setTipClickListener(TipClickListener listener) {
        this.listener = listener;
    }

    public TipDialog(Context context) {
        super(context);
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.tip_dialog, null);
        rollPagerView = (RollPagerView) view.findViewById(R.id.tip_roll);
        cancel = (ImageView) view.findViewById(R.id.tip_cancel);
        rollPagerView.setAdapter(new TipImageAdapter());
        rollPagerView.setHintView(new ColorPointHintView(context, Color.YELLOW, Color.WHITE));
        rollPagerView.setHintPadding(0, 0, 0, 60);
        cancel.setOnClickListener(this);
        setContentView(view);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tip_cancel:
                if (listener != null)
                    listener.onCancelClick();
                this.dismiss();
                break;
            case R.id.tip_jump:
                if (listener != null)
                    listener.onJumpClick();
                this.dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (listener != null) {
            listener.onNotShowChange(buttonView, isChecked);
        }
    }

    class TipImageAdapter extends StaticPagerAdapter {
        private int[] img = {
                R.drawable.tip_1,
                R.drawable.tip_2,
                R.drawable.tip_3,
                R.drawable.tip_4,
        };

        @Override
        public View getView(ViewGroup container, int position) {
            if (position == 3) {
                View view = LayoutInflater.from(container.getContext()).inflate(R.layout.tip_image, null);
                ImageView imageView = (ImageView) view.findViewById(R.id.tip_image);
                CheckBox notShow = (CheckBox) view.findViewById(R.id.tip_not_show);
                notShow.setOnCheckedChangeListener(TipDialog.this);
                imageView.setImageResource(img[position]);
                Button jump = (Button) view.findViewById(R.id.tip_jump);
                jump.setOnClickListener(TipDialog.this);
                return view;
            } else {
                ImageView view = new ImageView(container.getContext());
                view.setImageResource(img[position]);
                view.setScaleType(ImageView.ScaleType.CENTER_CROP);
                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                return view;
            }
        }

        @Override
        public int getCount() {
            return img.length;
        }
    }

    public interface TipClickListener {
        public void onCancelClick();

        public void onNotShowChange(CompoundButton buttonView, boolean isChecked);

        public void onJumpClick();
    }
}
